/**
 * 
 */
package it.unical.canonaco.rende.igpe.game.cbv.guilayer.gamemanagermenu.playdialog;

import java.awt.Checkbox;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

/**
 * @author Massimo Canonaco
 *
 */
public class JListCharacterRender extends JPanel implements ListCellRenderer<JListCharacterData> {

	private JLabel icon;
	
	private JCheckBox checkBox;
	
	private Dimension dimension;
	public JListCharacterRender()
	{
		super();
		icon = new JLabel();
		checkBox = new JCheckBox();
		
//		mcb.add(checkBox);
		add(checkBox);
		add(icon);
		dimension = new Dimension();
	}
	
	@Override
	public Component getListCellRendererComponent(
			JList<? extends JListCharacterData> list, JListCharacterData value,	int index, boolean isSelected, boolean cellHasFocus) 
	{
		if(isSelected)
			setBackground(Color.yellow);
		else
			setBackground(Color.black);
		
		icon.setIcon(value.getIcon());
		remove(checkBox);
		checkBox = value.getCheckBox();
		add(checkBox);
		
		dimension.setSize(icon.getWidth()+checkBox.getWidth()+4, Math.max(icon.getHeight(), checkBox.getHeight()));
//		System.out.println("DIMENSIONE COCO "+dimension.getWidth()+" "+dimension.getHeight());
		setMaximumSize(dimension);
		setAlignmentX(LEFT_ALIGNMENT);
		return this;
	}


}
